package com.identify.app.utils;

import android.view.View;

import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


/**
 * @author joyson
 * @create 2018-09-17
 */
public class RxViewUtils {
    /**
     * 防止重复点击
     *
     * @param target 目标view
     * @param listener 监听器
     */
    public static void preventRepeatedClick(final View target, int timeMillSecond,final View.OnClickListener listener) {
        RxView.clicks(target).throttleFirst(timeMillSecond, TimeUnit.MILLISECONDS).subscribe(new Observer<Object>() {
            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }

            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object object) {
                listener.onClick(target);
            }
        });
    }
}
